package com.example.springboot.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;

/**
 * 功能:定义拦截器配置
 * 作者: sdj
 * 日期: 2024/12/15 22:50
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor()) //配置jwt的拦截器规则
                .addPathPatterns("/**") //拦截所有的请求路径
                .excludePathPatterns("/login","/register");   //放行/login请求
        super.addInterceptors(registry);
    }

    @Bean
    public JWTInterceptor jwtInterceptor(){
        return new JWTInterceptor();  //new拦截器规则
    }
}
